package com.inkyi.assistant.app;


import com.formdev.flatlaf.extras.FlatSVGIcon;
import com.formdev.flatlaf.icons.FlatFileViewComputerIcon;
import com.inkyi.assistant.app.console.RunConsolePanel;
import com.inkyi.assistant.app.notepad.NoteListingsPanel;
import com.inkyi.assistant.app.notepad.NotepadMain;
import com.inkyi.assistant.app.todolist.TodoListMain;
import com.inkyi.assistant.app.tools.ToolListingsPanel;
import com.inkyi.assistant.core.AssistantCoreApplication;
import com.inkyi.framework.daqian.ease.EaseComponent;
import com.inkyi.framework.daqian.ease.EaseGui;
import com.inkyi.framework.daqian.ease.EaseGuiHelper;
import com.inkyi.framework.daqian.gui.InkGui;
import com.inkyi.framework.daqian.gui.InkGuiHelper;
import com.inkyi.framework.daqian.gui.consts.InkGuiConstants;
import com.inkyi.framework.daqian.gui.core.DockContent;
import com.inkyi.framework.daqian.gui.core.Workspace;
import com.inkyi.framework.daqian.gui.tab.DockTabItem;
import com.inkyi.framework.daqian.gui.tab.DockTabViewBase;
import com.inkyi.framework.daqian.share.consts.InkGuiDirection;
import com.inkyi.framework.daqian.share.consts.InkGuiPosition;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.UUID;

public class AssistantAppApplication {


    public static void main(String[] args) {
        AssistantCoreApplication.main(args);
        fun2();
    }


    private static void fun2() {
        EaseGuiHelper.setProperty(InkGuiConstants.PROP_GUI_TITLE, "墨一工作台");
        EaseGuiHelper.setProperty(InkGuiConstants.PROP_GUI_WIDTH, 1280);
        EaseGuiHelper.setProperty(InkGuiConstants.PROP_GUI_HEIGHT, 800);

        Image iconImage = new FlatSVGIcon("icons/desktopicon.svg").getImage();
        EaseGuiHelper.setProperty(InkGuiConstants.PROP_GUI_APP_ICON, iconImage);
        EaseGui.setup();
        //记事本
        {
            Icon icon = new FlatSVGIcon("icons/words.svg", 14, 14);
            EaseComponent ec = new EaseComponent();
            ec.setTitle("待办");
            ec.setIcon(icon);
            ec.setSupplier(NotepadMain::new);
            EaseGuiHelper.addComponent(ec);
        }
        // 待办
        {
            Icon icon = new FlatSVGIcon("icons/todolist/todo.svg", 14, 14);
            EaseComponent ec = new EaseComponent();
            ec.setTitle("待办");
            ec.setIcon(icon);
            ec.setSupplier(TodoListMain::new);
            EaseGuiHelper.addComponent(ec);
        }
        EaseGui.setVisible(true);
    }

    private static void fun1() {

        InkGuiHelper.setProperty(InkGuiConstants.PROP_GUI_TITLE, "墨一工作台");
        InkGuiHelper.setProperty(InkGuiConstants.PROP_GUI_WIDTH, 1280);
        InkGuiHelper.setProperty(InkGuiConstants.PROP_GUI_HEIGHT, 800);

        Image iconImage = new FlatSVGIcon("icons/desktopicon.svg").getImage();
        InkGuiHelper.setProperty(InkGuiConstants.PROP_GUI_APP_ICON, iconImage);
        InkGui.setup();
        //记事本
        {
            NoteListingsPanel compPanel = new NoteListingsPanel();
            DockTabItem tabItem = new DockTabItem("笔记", new FlatFileViewComputerIcon(), new DockTabViewBase("笔记") {{
                setPartContent(compPanel);
            }});
            InkGuiHelper.addDockTabItem(InkGuiPosition.LEFT_TOP, tabItem);
            InkGuiHelper.getDockSideBar(InkGuiPosition.LEFT_TOP).setSelectedExcept(tabItem, true);
        }
        //待办
        {
            Icon icon = new FlatSVGIcon("icons/console.svg", 14, 14);
            DockTabItem tabItem = new DockTabItem("待办", icon, new DockTabViewBase("待办") {{
                setPartContent(new JPanel());
            }});
            tabItem.addActionListener(new ActionListener() {
                String todoId = UUID.randomUUID().toString();
                TodoListMain compPanel = new TodoListMain();

                @Override
                public void actionPerformed(ActionEvent e) {
                    Workspace workspace = InkGuiHelper.getWorkspace();
                    DockContent dockContent = InkGuiHelper.getDockContent(InkGuiDirection.LEFT.getCode());
                    if (dockContent != null) {
                        dockContent.setVisible(false);
                    }
                    if (!workspace.existTabComp(todoId)) {
                        workspace.addTabComp(todoId, "待办详情", compPanel);
                    } else {
                        workspace.openTabComp(todoId);
                    }
                }
            });
            InkGuiHelper.addDockTabItem(InkGuiPosition.LEFT_TOP, tabItem);
            InkGuiHelper.getDockSideBar(InkGuiPosition.LEFT_TOP).setSelectedExcept(tabItem, true);
        }
        //小工具
        {
            ToolListingsPanel compPanel = new ToolListingsPanel();
            DockTabItem tabItem = new DockTabItem("小工具", new FlatFileViewComputerIcon(), new DockTabViewBase("小工具") {{
                setPartContent(compPanel);
            }});
            InkGuiHelper.addDockTabItem(InkGuiPosition.RIGHT_TOP, tabItem);
        }

        //控制台
        {
            RunConsolePanel compPanel = new RunConsolePanel();
            Icon icon = new FlatSVGIcon("icons/console.svg", 14, 14);
            DockTabItem tabItem = new DockTabItem("控制台", icon, new DockTabViewBase("控制台") {{
                setPartContent(compPanel);
            }});
            InkGuiHelper.addDockTabItem(InkGuiPosition.BOTTOM_LEFT, tabItem);
        }
        InkGui.setVisible(true);
    }


}
